package com.abel.bigwater.data.jnrq

import com.alibaba.fastjson.JSON
import org.joda.time.Period
import org.junit.Assert.*
import org.junit.Test
import org.slf4j.LoggerFactory

class JnrqDeviceTest {
    @Test
    fun test11Period() {
        val d = JnrqDevice().apply {
            address = "12345"
            firmId = "31"
        }

        val str: String? = null
        lgr.info("starts-with: {}", str.orEmpty().startsWith("2108"))
        lgr.info("period: {}", Period(12, 0, 0, 0))
        lgr.info("parsed period: {}", Period.parse("PT00H30M"))
        lgr.info("jnrq-device: {}", JSON.toJSONString(d, true))
    }

    @Test
    fun test12PeriodBadFmt() {
        val d = JnrqDevice().apply {
            address = "12345"
            firmId = "31"

            uploadPeriod = "123M"
            readPeriod = "0M"
        }
        lgr.info("invalid fmt: {}", JSON.toJSONString(d, true))
    }

    @Test
    fun test13PeriodTooSmall() {
        val d = JnrqDevice().apply {
            address = "12345"
            firmId = "31"

            uploadPeriod = "PT5M"
            readPeriod = "PT1M"
        }
        lgr.info("invalid fmt: {}", JSON.toJSONString(d, true))
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(JnrqDeviceTest::class.java)
    }
}